/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import model.Setor;
import util.jpaUtil;

/**
 *
 * @author calandreli
 */
public class SetorDAO extends JPAHibernateDAO{
  public Statement stm;
    public ResultSet rs;
    public Connection conn;
    
    
    @Override
    public Class obterClasse() {
        return Setor.class;
    }
    
        
   public List<Setor> pesquisarSetors(String descricao) {
        EntityManager em = jpaUtil.getEntityManager();
        Query query = em.createQuery("Select t from Setor t  where LOWER(t.nome)  like :nomeSetor OR UPPER(t.nome)  like :nomeSetor");
        query.setParameter("descricao", "" + descricao.toLowerCase() + "%");
        
        return query.getResultList();
    }
   
    public List<Setor> pesquisarSetorSigla(String sigla) {
        EntityManager em = jpaUtil.getEntityManager();
        Query query = em.createQuery("Select t from Setor t  where LOWER(t.sigla)  like :sigla OR UPPER(t.sigla)  like :sigla");
        query.setParameter("sigla", "" + sigla.toLowerCase() + "%");
        
        return query.getResultList();
    }
    
     public Setor pesquisarSetorSiglaSingle(String sigla) {
        EntityManager em = jpaUtil.getEntityManager();
        Query query = em.createQuery("Select t from Setor t  where LOWER(t.sigla)  like :sigla OR UPPER(t.sigla)  like :sigla");
        query.setParameter("sigla", "" + sigla.toLowerCase() + "%");
        return (Setor) query.getSingleResult();
    }

    public List<Setor> pesquisarSetorsCod(int codSetor) {
        EntityManager em = jpaUtil.getEntityManager();
        Query query = em.createQuery("Select t from Setor t where t.id_setor = :codSetor");
        query.setParameter("codSetor", codSetor);

        return query.getResultList();
    }

//    public void execSQL(String sql){
//       try{
//           stm= conn.createStatement(rs.TYPE_SCROLL_INSENSITIVE,rs.CONCUR_READ_ONLY);
//           rs= stm.executeQuery(sql);
//       }catch(SQLException e){         
//       }
//    }
    
    
}
